﻿using SmartSpace.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SmartSpace.Tasks
{
    public class TaskService : ITaskService
    {
        public ServiceResult CreateTask(TaskMessage message)
        {
            using (TaskDbContext context = new TaskDbContext())
            {
                EntityRepository.Save<TaskMessage>(message, context);
                return new ServiceResult(EntityRepository.Commit(context));
            }
        }

        public PagedResult<TaskMessage> GetTasks(string account, int start, int limit)
        {
            using (TaskDbContext context = new TaskDbContext())
            {
                List<TaskMessage> list = context.Set<TaskMessage>().Where(p => p.Receiver == account).ToList();

                return new PagedResult<TaskMessage>(0, 25, list.Count, list);
            }
        }
    }
}
